Skip to content

Automated Test: sms-retry-enhanced #380

Closed
wants to merge 1 commit into from

Conversation

admin-coderabbit
Copy link
Owner

@admin-coderabbit admin-coderabbit commented Feb 4, 2026

This pull request was automatically created by @coderabbitai/e2e-reviewer.

Batch created pull request.

Summary by CodeRabbit

  • New Features

    • Added retry logic for SMS reminders to improve delivery reliability when initial scheduling attempts fail.
  • Improvements

    • Enhanced automatic cleanup of failed SMS reminders with multiple failed attempts.
    • Improved error tracking for reminder scheduling failures.

* add retry count to workflow reminder

* add logic to for retry count

---------

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
@coderabbit-eval
Copy link

coderabbit-eval bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

This pull request introduces a retry count mechanism for workflow SMS reminders. A new retryCount field is added to the WorkflowReminder model via schema and migration, and the SMS scheduling logic is updated to track and increment retry counts when scheduling fails or errors occur.

Changes

Cohort / File(s) Summary
Database Schema
packages/prisma/schema.prisma, packages/prisma/migrations/20240508134359_add_retry_count_to_workflow_reminder/migration.sql
Added retryCount Int @default(0) field to WorkflowReminder model with corresponding database migration.
SMS Scheduling Logic
packages/features/ee/workflows/api/scheduleSMSReminders.ts
Updated cleanup criteria to delete reminders where retryCount > 1 or scheduling time is past. Modified query to include retryCount in results. Added logic to increment retryCount on scheduling failure and in error handling paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A fluffy reminder hops once more,
If SMS doesn't work, it'll retry, for sure!
Count goes up, each bounce down the line,
With retries tracked, the timing's just fine! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Automated Test: sms-retry-enhanced' is vague and generic, using non-descriptive terms that don't convey meaningful information about the actual changeset. Replace the generic title with a descriptive summary of the main change, such as 'Add retry count tracking to SMS workflow reminders' to clearly communicate the changeset's primary purpose.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sms-retry-enhanced

Comment @coderabbit eval help to get the list of available commands and usage tips.

@coderabbit-eval coderabbit-eval bot closed this Feb 4, 2026
Copy link

@coderabbit-eval coderabbit-eval bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@packages/features/ee/workflows/api/scheduleSMSReminders.ts`:
- Around line 189-198: The catch block that calls prisma.workflowReminder.update
can itself throw and abort the enclosing for loop; wrap the retryCount update in
its own try-catch (or append a .catch()) so failures to increment
reminder.retryCount are swallowed/logged and do not rethrow. Specifically,
protect the prisma.workflowReminder.update call that uses reminder.id and
reminder.retryCount inside scheduleSMSReminders.ts (inside the outer catch) with
a nested try/catch (or use prisma.workflowReminder.update(...).catch(...)) and
log the update error without throwing so the loop continues processing remaining
reminders.
- Around line 31-43: The OR branch currently deletes reminders with retryCount >
1 regardless of method; update the condition so the second alternative also
requires method === WorkflowMethods.SMS (i.e., make the OR array entry include
both { method: WorkflowMethods.SMS, retryCount: { gt: 1 } }) so only SMS
reminders are matched for the retryCount-based deletion; modify the OR clause
around WorkflowMethods.SMS, scheduledDate and retryCount to include this method
filter.

Comment on lines +31 to +43
OR: [
{
method: WorkflowMethods.SMS,
scheduledDate: {
lte: dayjs().toISOString(),
},
},
{
retryCount: {
gt: 1,
},
},
],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if retryCount is used/incremented by other workflow method handlers (email, whatsapp)
rg -n "retryCount" --type=ts -C 3

Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror

Length of output: 4246


🏁 Script executed:

#!/bin/bash
# Search for other workflow reminder handlers
fd -e ts -path "*/workflows/*" "schedule.*Reminders" 

echo "---"

# Search for WorkflowReminder model/schema definition
fd -e ts -o -e prisma | xargs rg -l "WorkflowReminder" | head -20

Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror

Length of output: 1793


🏁 Script executed:

#!/bin/bash
# Check if email and whatsapp handlers use retryCount
echo "=== WHATSAPP HANDLER ===" 
rg -n "retryCount" packages/features/ee/workflows/api/scheduleWhatsappReminders.ts

echo ""
echo "=== EMAIL HANDLER ===" 
rg -n "retryCount" packages/features/ee/workflows/api/scheduleEmailReminders.ts

echo ""
echo "=== MIGRATION FILE ===" 
cat packages/prisma/migrations/20240508134359_add_retry_count_to_workflow_reminder/migration.sql

Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror

Length of output: 262


🏁 Script executed:

#!/bin/bash
# Get the full WHERE clause context to understand the delete operation
sed -n '25,50p' packages/features/ee/workflows/api/scheduleSMSReminders.ts

Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror

Length of output: 657


🏁 Script executed:

#!/bin/bash
# Get more context around the delete operation including what happens after
sed -n '28,65p' packages/features/ee/workflows/api/scheduleSMSReminders.ts

Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror

Length of output: 961


🏁 Script executed:

#!/bin/bash
# Check the catch block and surrounding code to verify the update error handling
sed -n '165,200p' packages/features/ee/workflows/api/scheduleSMSReminders.ts

Repository: admin-coderabbit/coderabbit-cal_dot_com-mirror

Length of output: 917


Add method filter to retryCount deletion condition to prevent unintended removal of non-SMS reminders.

The second OR branch deletes any WorkflowReminder with retryCount > 1, regardless of method. While currently only the SMS handler increments retryCount (keeping email/WhatsApp reminders at 0), this is a logic error that could cause issues if retry logic is added to other methods in the future.

Proposed fix
       OR: [
         {
           method: WorkflowMethods.SMS,
           scheduledDate: {
             lte: dayjs().toISOString(),
           },
         },
         {
+          method: WorkflowMethods.SMS,
           retryCount: {
             gt: 1,
           },
         },
       ],
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
OR: [
{
method: WorkflowMethods.SMS,
scheduledDate: {
lte: dayjs().toISOString(),
},
},
{
retryCount: {
gt: 1,
},
},
],
OR: [
{
method: WorkflowMethods.SMS,
scheduledDate: {
lte: dayjs().toISOString(),
},
},
{
method: WorkflowMethods.SMS,
retryCount: {
gt: 1,
},
},
],
🤖 Prompt for AI Agents
In `@packages/features/ee/workflows/api/scheduleSMSReminders.ts` around lines 31 -
43, The OR branch currently deletes reminders with retryCount > 1 regardless of
method; update the condition so the second alternative also requires method ===
WorkflowMethods.SMS (i.e., make the OR array entry include both { method:
WorkflowMethods.SMS, retryCount: { gt: 1 } }) so only SMS reminders are matched
for the retryCount-based deletion; modify the OR clause around
WorkflowMethods.SMS, scheduledDate and retryCount to include this method filter.

Comment on lines 189 to 198
} catch (error) {
await prisma.workflowReminder.update({
where: {
id: reminder.id,
},
data: {
retryCount: reminder.retryCount + 1,
},
});
console.log(`Error scheduling SMS with error ${error}`);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

The prisma.update in the catch block can throw and abort processing of remaining reminders.

If the retryCount update on Line 190 fails (e.g., DB connectivity issue), the error propagates out of the catch block and the for loop, skipping all subsequent unscheduled reminders and potentially returning a 500 instead of the 200 on Line 201.

Wrap this in a nested try-catch or use .catch() to ensure the loop continues.

🛡️ Proposed fix
     } catch (error) {
-      await prisma.workflowReminder.update({
-        where: {
-          id: reminder.id,
-        },
-        data: {
-          retryCount: reminder.retryCount + 1,
-        },
-      });
+      try {
+        await prisma.workflowReminder.update({
+          where: {
+            id: reminder.id,
+          },
+          data: {
+            retryCount: reminder.retryCount + 1,
+          },
+        });
+      } catch (updateError) {
+        console.log(`Error updating retryCount for reminder ${reminder.id}: ${updateError}`);
+      }
       console.log(`Error scheduling SMS with error ${error}`);
     }
🤖 Prompt for AI Agents
In `@packages/features/ee/workflows/api/scheduleSMSReminders.ts` around lines 189
- 198, The catch block that calls prisma.workflowReminder.update can itself
throw and abort the enclosing for loop; wrap the retryCount update in its own
try-catch (or append a .catch()) so failures to increment reminder.retryCount
are swallowed/logged and do not rethrow. Specifically, protect the
prisma.workflowReminder.update call that uses reminder.id and
reminder.retryCount inside scheduleSMSReminders.ts (inside the outer catch) with
a nested try/catch (or use prisma.workflowReminder.update(...).catch(...)) and
log the update error without throwing so the loop continues processing remaining
reminders.

Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant